﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ddcCajamarca.BusinessEntities.Directorio;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;

namespace ddcCajamarca.Repository.Mapping
{
    public class OrganizacionMap : EntityTypeConfiguration<Organizacion>
    {
        public OrganizacionMap()
        {
            this.HasKey(c => c.Id);

            this.Property(c => c.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(c => c.IdTipoOrganizacion)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(c => c.IdSubTipoOrganizacion)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(c => c.IdUbigeo)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(c => c.Ruc)
                .HasMaxLength(11)
                .IsOptional();

            this.Property(c => c.Nombre)
                .HasMaxLength(125)
                .IsRequired();

            this.Property(c => c.Direccion)
                .HasMaxLength(250)
                .IsOptional();

            this.Property(c => c.Telefono)
                .HasMaxLength(10)
                .IsRequired();

            this.Property(c => c.Telefono2)
                .HasMaxLength(10)
                .IsOptional();

            this.Property(c => c.Email)
                .HasMaxLength(100)
                .IsOptional();

            this.Property(c => c.PaginaWeb)
                .HasMaxLength(500)
                .IsOptional();

            this.Property(c => c.Logo)
                .IsOptional();

            this.Property(c => c.InstituciónVinculada)
                .IsRequired();

            this.ToTable("Organizacion");
            this.Property(c => c.Id).HasColumnName("Id");
            this.Property(c => c.Ruc).HasColumnName("Ruc");
            this.Property(c => c.IdTipoOrganizacion).HasColumnName("IdTipoOrganizacion");
            this.Property(c => c.IdSubTipoOrganizacion).HasColumnName("IdSubTipoOrganizacion");
            this.Property(c => c.IdUbigeo).HasColumnName("IdUbigeo");
            this.Property(c => c.Nombre).HasColumnName("Nombre");
            this.Property(c => c.Direccion).HasColumnName("Direccion");
            this.Property(c => c.Telefono).HasColumnName("Telefono");
            this.Property(c => c.Telefono2).HasColumnName("Telefono2");
            this.Property(c => c.Email).HasColumnName("Email");
            this.Property(c => c.PaginaWeb).HasColumnName("PaginaWeb");
            this.Property(c => c.Logo).HasColumnName("Logo");

            this.HasOptional(c => c.TipoOrganizacion)
                .WithMany(c => c.Organizaciones)
                .HasForeignKey(t => t.IdTipoOrganizacion)
                .WillCascadeOnDelete(false);

            this.HasOptional(c => c.SubTipoInstitucion)
                .WithMany(c => c.Organizacion)
                .HasForeignKey(t => t.IdSubTipoOrganizacion)
                .WillCascadeOnDelete(false);

            this.HasRequired(c => c.Ubigeo)
                .WithMany(c => c.Organizaciones)
                .HasForeignKey(t => t.IdUbigeo)
                .WillCascadeOnDelete(false);
        }
    }
}
